/*****************************************************************************\
 *                            RESTRICTED RIGHTS LEGEND
 *
 *      Use, duplication, or disclosure by the Government is subject to
 *      restrictions as set forth in subparagraph (c) (1) (ii) of the Rights in
 *      Technical Data and Computer Software Clause at DFARS 252.227-7013.
 *
 *      The Board of Trustees of the University of Illinois
 *      109 Coble Hall
 *      801 South Wright Street
 *      Champaign, IL 61820-6242
 *
 *      File: MemoryProvider.cs
 *
 *      Authors: Erich Heine, David Rodgers, Denis Kholine, Derek Dagit,
 *      William H. Sanders, Klara Nahrstedt, Rakesh Bobba, Tim Yardley
 *      Creation Date: 2012
 *
 *      Copyright (c) 2012 William H. Sanders, Klara Nahrstedt, Erich Heine,
 *      Rakesh Bobba, Tim Yardley,
 *      and The Board of Trustees of the University of Illinois
 *      All rights reserved.
 * 
 *      No further use, distribution, or disclosure beyond internal development 
 *      project participants (Grid Protection Alliance and University of Illinois)
 *      is allowed.
 *
 \*****************************************************************************/

﻿using System.Collections.Generic;
using System.Linq;

namespace SIEGate.Acl
{
    public class MemoryProvider : IAclProvider
    {
        private HashSet<AccessRule> rules
        {
            get;
            set;
        }

        public MemoryProvider()
        {
            this.rules = new HashSet<AccessRule>();
        }



        #region IAclProvider members



        public IEnumerable<AccessRule> GetAclsBySubject(params Subject[] subjects)
        {
            return this.rules.Where(rule => subjects.Contains(rule.subject));
        }


        public IAclProvider AddAcls(params AccessRule[] rules)
        {
            foreach (AccessRule rule in rules)
            {
                this.rules.Add(rule);
            }

            return this;
        }

        public IAclProvider DeleteAcls(params AccessRule[] rules)
        {
            foreach (AccessRule rule in rules)
            {
                this.rules.Remove(rule);
                AclWasDeleted(this, new AclChangedEventArgs(rule));
            }

            return this;
        }

        public event AclChangedHandler AclWasDeleted;

        #endregion

    }
}
